<%@page import="org.json.simple.JSONArray"%>
<%@page import="vo.StudyVo"%>
<%@page import="java.util.List"%>
<%@page import="dao.StudyDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("utf-8");
	String menu_no = request.getParameter("menu_no");
	String titleNo = request.getParameter("title_no");
	String state = request.getParameter("state");
	String new_name = request.getParameter("title_name");
	
	
	
	System.out.println(menu_no);
	System.out.println(titleNo);
	System.out.println(state);
	
	
	
	StudyDao dao =StudyDao.getDao();
	List<StudyVo> list = null;
	int cate_no=0;

	if(titleNo!=null && state!=null){//swap처리
		int title_no = Integer.parseInt(titleNo);
		int title_step = dao.titleStep(title_no);
		cate_no = dao.titleCateNo(title_no);
		
		if(state.equals("up")){
			System.out.println("up");
			dao.titleStepDown(title_step-1);
			dao.titleUp(title_no);
		}else if(state.equals("down")){
			System.out.println("down");
			dao.titleStepUp(title_step+1);
			dao.titleDown(title_no);
		}else if(state.equals("rename")){
			StudyVo svo = new StudyVo();
			svo.setTitle_no(title_no);
			svo.setTitle_name(new_name);
			dao.titleRename(svo);
			
		}else if(state.equals("delete")){
			
		}
		
	}
	
	list = dao.selectTitle(cate_no);
	
	JSONArray jarr = new JSONArray();
	jarr.addAll(list);
	out.println(jarr.toString());
%>